package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MainActivity extends AppCompatActivity {

    private DBUtils db = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        Button btn_login = findViewById(R.id.button_login);
        EditText edit_username = findViewById(R.id.editText_username);
        EditText edit_password = findViewById(R.id.editText_password);
        db = new DBUtils();

        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username = edit_username.getText().toString();
                String password = edit_password.getText().toString();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        if(db.LinkMysql() && db.LoginQuery(username,password)){
                            System.out.println("登录成功！");
                            finish();
                            Intent intent=new Intent(MainActivity.this,BaseActivity.class);
                            startActivity(intent);
                        }else{
                            System.out.println("登录失败！");
                        }
                    }
                }).start();
            }
        });
    }
}
